import sys
import chardet
import random
import os

current_file_path = os.path.abspath(__file__)
current_folder = os.path.dirname(current_file_path)

filterwords = []
with open(current_folder+"/conf/filter-word.txt", "rb") as f:
    result=chardet.detect(f.read())

with open(current_folder+"/conf/filter-word.txt", "r",encoding=result["encoding"]) as f:
    for line in f:
        filterwords.append(line.split("\n")[0])

familywords = []
with open(current_folder+"/conf/family-word.txt", "r",encoding=result["encoding"]) as f:
    for line in f:
        familywords.append(line.split("\n")[0])

dual_word_probability=2

if len(sys.argv) > 1:
    count = sys.argv[1]
    for i in range(int(count)):
        print(str(i+1)+". "+random.choice(familywords) +
              random.choice(filterwords)+(random.choice(filterwords) if random.randint(1,10)>dual_word_probability else ""))
else:
    print(random.choice(familywords) +
          random.choice(filterwords)+(random.choice(filterwords)if random.randint(1,10)>dual_word_probability else ""))
